﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace WPlayer
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                WangfsLib.Interface.VlcPlayer.VlcMediaPlayer.ShowConsole();
                if (!System.IO.File.Exists(args[0]))
                {
                    Console.WriteLine("确保文件 \"{0}\" 存在", args[0]);
                    return;
                }
                string src = args[0], des;
                des = args.Length > 1 ? args[1] : System.IO.Path.ChangeExtension(src, "mda");
                if (System.IO.File.Exists(des))
                {
                    Console.WriteLine("保存路径已经存在文件！");
                    return;
                }
                string pwd = null;
                if (args.Length > 2) pwd = args[2];
                byte rate = 0;
                WangfsLib.Interface.VlcPlayer.VlcMediaPlayer.EncodeMediaFile(src, des, (f, p) =>
                {
                    if (rate != p) Console.WriteLine("当前进度:{0}", rate = p);
                    return false;
                }, pwd);
                Console.WriteLine("加密完成！");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            string[] dlls = { "libvlc.dll", "libvlccore.dll" };
            foreach (var dll in dlls)
            {
                if (!System.IO.File.Exists(System.IO.Path.Combine(Application.StartupPath, dll)))
                {
                    MessageBox.Show(string.Format("应用程序目录下没有动态库：{0}", dll));
                    return;
                }
            }
            if (!System.IO.Directory.Exists(System.IO.Path.Combine(Application.StartupPath, "plugins")))
            {
                MessageBox.Show("应用程序目录下没有 vlc 的插件目录：plugins");
                return;
            }

            Application.Run(new Form1());
        }

        public static bool IsInvalidFile(string file)
        {
            string[] exts = { "7Z", "ARJ", "ASF", "GZ", "GZIP", "IMG", "ISO", "LZH", "MSI", "MSU", "PDF",
                "PLJ", "PPS", "PPT", "PPTX", "QT", "TXT", "RA", "RAR", "SEA", "SIT", "SITX", "TAR", "TIF",
                "TIFF", "Z", "ZIP", "DOC", "DOCX", "XML", "HTM", "HTML", "XLS", "XLSX", "CSV" };
            return exts.Contains(System.IO.Path.GetExtension(file).Substring(1).ToUpper());
        }
    }
}
